package com.tlias.controller;

import com.tlias.jwt.annotation.LoginToken;
import com.tlias.jwt.service.JwtEmpService;
import com.tlias.jwt.service.TokenService;
import com.tlias.pojo.Dept;
import com.tlias.pojo.Result;
import com.tlias.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class DeptController {
    @Autowired
    DeptService deptService;

    /**
     * 部门列表查询
     * @return
     */
    @LoginToken
    @GetMapping("/depts")
    public Result getDeptListController(){
        return deptService.getDeptListService();
    }

    /**
     * 新增部门
     * @param
     * @return
     */
    @LoginToken
    @PostMapping("/depts")
    public Result addDeptController(@RequestBody Dept dept){
        Result result = deptService.addDeptService(dept.getName());
        return result;
    }

    @LoginToken
    @PutMapping("/depts")
    public Result updateDeptController(@RequestBody Dept dept){
        return deptService.updateDept(dept);
    }

    @LoginToken
    @DeleteMapping("/depts/{id}")
    public Result deleteDept(@PathVariable Integer id){
        Result result = deptService.delectDeptById(id);
        return result;
    }

    @LoginToken
    @GetMapping("/depts/{id}")
    public Result findDeptByIdController(@PathVariable Integer id){
        System.out.println("id" + id);
        return deptService.FindDeptById(id);
    }

}
